<template>
  <a-dropdown placement="bottomRight">
    <a-button type="text" class="language-switcher">
      <GlobalOutlined />
      <span class="language-text">{{ currentLanguageName }}</span>
      <DownOutlined />
    </a-button>
    <template #overlay>
      <a-menu @click="handleLanguageChange">
        <a-menu-item 
          v-for="(name, locale) in LOCALE_NAMES" 
          :key="locale"
          :class="{ 'active-language': locale === localeStore.currentLocale }"
        >
          <CheckOutlined 
            v-if="locale === localeStore.currentLocale" 
            class="check-icon"
          />
          {{ name }}
        </a-menu-item>
      </a-menu>
    </template>
  </a-dropdown>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useLocaleStore } from '@/stores/locale'
import { LOCALE_NAMES } from '@/locales'
import {
  GlobalOutlined,
  DownOutlined,
  CheckOutlined
} from '@ant-design/icons-vue'

const localeStore = useLocaleStore()

// 当前语言显示名称
const currentLanguageName = computed(() => {
  return LOCALE_NAMES[localeStore.currentLocale]
})

// 处理语言切换
const handleLanguageChange = ({ key }: { key: string }) => {
  localeStore.setLocale(key as any)
}
</script>

<style lang="less" scoped>
.language-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.3s;
  
  &:hover {
    background-color: rgba(0, 0, 0, 0.04);
  }
}

.language-text {
  font-size: 14px;
}

:deep(.ant-menu-item) {
  &.active-language {
    background-color: #f0f0f0;
    font-weight: 500;
  }
}

.check-icon {
  margin-right: 8px;
  color: #1890ff;
}
</style> 